{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from bs4 import BeautifulSoup\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [],
   "source": [
    "with open(\"./detail.html\", \"r\", encoding=\"utf8\") as f:\n",
    "    html = f.read()\n",
    "    bs = BeautifulSoup(html, \"html.parser\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "<div class=\"ops\"><span class=\"like\" title=\"点赞数113179\"><!-- --><!-- --><!-- --><!-- --><i class=\"van-icon-videodetails_like\" style=\"color:;\"></i>11.3万\n    </span><span class=\"coin\" title=\"投硬币枚数\"><canvas class=\"ring-progress\" height=\"34\" style=\"width:34px;height:34px;left:-3px;top:-3px;\" width=\"34\"></canvas>\n<!-- --><i class=\"van-icon-videodetails_throw\" style=\"color:;\"></i>\n      2.4万\n    </span><span class=\"collect\" title=\"收藏人数\"><canvas class=\"ring-progress\" height=\"34\" style=\"width:34px;height:34px;left:-3px;top:-3px;\" width=\"34\"></canvas>\n<!-- --><i class=\"van-icon-videodetails_collec\" style=\"color:;\"></i>6.7万\n    </span><span class=\"share\" title=\"分享\"><i class=\"van-icon-videodetails_share\"></i>2.6万\n                    <!-- --></span></div>"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ops = bs.find(\"div\", {\"class\", \"ops\"})\n",
    "ops"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.3万\n",
      "2.4万\n",
      "6.7万\n",
      "2.6万\n"
     ]
    }
   ],
   "source": [
    "span = ops.findAll(\"span\")\n",
    "for s in span:\n",
    "    print(s.text.strip())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "'4582'"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dm = bs.find(\"span\", {\"class\":\"dm\"})\n",
    "dm.text[:-2]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "<ul class=\"tag-area clearfix\">\n<li class=\"tag\">\n<div><a class=\"tag-link\" href=\"//www.bilibili.com/v/channel/127846?tab=featured\" target=\"_blank\"><img class=\"channel-icon\" height=\"32\" src=\"\" width=\"32\"/><span class=\"channel-name\">罗翔</span></a>\n<!-- --></div>\n</li>\n<li class=\"tag\">\n<div><a class=\"tag-link\" href=\"//www.bilibili.com/v/channel/40737?tab=featured\" target=\"_blank\"><img class=\"channel-icon\" height=\"32\" src=\"\" width=\"32\"/><span class=\"channel-name\">人文</span></a>\n<!-- --></div>\n</li>\n<li class=\"tag\"><a class=\"tag-link\" href=\"//www.bilibili.com/v/technology/\" target=\"_blank\"><span>知识</span></a></li>\n<li class=\"tag\"><a class=\"tag-link\" href=\"//www.bilibili.com/v/technology/fun/\" target=\"_blank\"><span>社科人文</span></a></li>\n<li class=\"tag\">\n<div><a class=\"tag-link\" href=\"//search.bilibili.com/all?keyword=%E7%A4%BE%E4%BC%9A&amp;from_source=video_tag\" target=\"_blank\">\n                            社会\n                        </a><!-- --><!-- --></div>\n</li>\n<li class=\"tag\">\n<div><a class=\"tag-link\" href=\"//search.bilibili.com/all?keyword=%E5%AD%A6%E4%B9%A0&amp;from_source=video_tag\" target=\"_blank\">\n                            学习\n                        </a><!-- --><!-- --></div>\n</li>\n<li class=\"tag\">\n<div><a class=\"tag-link\" href=\"//search.bilibili.com/all?keyword=%E7%88%B1%E6%83%85&amp;from_source=video_tag\" target=\"_blank\">\n                            爱情\n                        </a><!-- --><!-- --></div>\n</li>\n<li class=\"tag\">\n<div><a class=\"tag-link\" href=\"//search.bilibili.com/all?keyword=%E5%BC%A0%E4%B8%89&amp;from_source=video_tag\" target=\"_blank\">\n                            张三\n                        </a><!-- --><!-- --></div>\n</li><!-- --><!-- --><!-- --></ul>"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tags = bs.find(\"ul\", {\"class\":\"tag-area clearfix\"})\n",
    "tags"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "outputs": [
    {
     "data": {
      "text/plain": "'罗翔,人文,知识,社科人文,社会,学习,爱情,张三'"
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts = []\n",
    "tcs = tags.find_all(\"li\")\n",
    "for tc in tcs:\n",
    "    ts.append(tc.text.strip())\n",
    "ts\n",
    "\",\".join(ts)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'text'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mAttributeError\u001B[0m                            Traceback (most recent call last)",
      "\u001B[1;32m<ipython-input-42-d9a0dcc47030>\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[0minfo\u001B[0m \u001B[1;33m=\u001B[0m \u001B[0mbs\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mfind\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"div\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;33m{\u001B[0m\u001B[1;34m\"class\"\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;34m\"info open\"\u001B[0m\u001B[1;33m}\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mtext\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mstrip\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"\"\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mreplace\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"\\n\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\",\"\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mreplace\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\" \"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\"\"\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m----> 2\u001B[1;33m \u001B[0minfo\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mtext\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mstrip\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"\"\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mreplace\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"\\n\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\",\"\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mreplace\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\" \"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\"\"\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m",
      "\u001B[1;31mAttributeError\u001B[0m: 'str' object has no attribute 'text'"
     ]
    }
   ],
   "source": [
    "info = bs.find(\"div\", {\"class\":\"info open\"}).text.strip(\"\").replace(\"\\n\", \",\").replace(\" \", \"\")\n",
    "info.text.strip(\"\").replace(\"\\n\", \",\").replace(\" \", \"\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "outputs": [
    {
     "data": {
      "text/plain": "[1, 2, 3, 4, 5]"
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [1, 2, 3, 4, 5, 6]\n",
    "a.pop()\n",
    "a"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3]\n"
     ]
    },
    {
     "data": {
      "text/plain": "[1, 2]"
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = (1, 2, 3)\n",
    "a = list(a)\n",
    "print(a)\n",
    "a.pop()\n",
    "a"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h\n"
     ]
    }
   ],
   "source": [
    "if []:\n",
    "    print(\"hello\")\n",
    "else:\n",
    "    print(\"h\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "outputs": [
    {
     "data": {
      "text/plain": "'1,2'"
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\",\".join([str(i) for i in a])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unhashable type: 'dict'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "\u001B[1;32m<ipython-input-80-8a0c0b701474>\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m      5\u001B[0m     \u001B[1;33m{\u001B[0m\u001B[1;34m'https'\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;34m'202.95.8.141:3128'\u001B[0m\u001B[1;33m}\u001B[0m\u001B[1;33m,\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m      6\u001B[0m     \u001B[1;33m{\u001B[0m\u001B[1;34m'https'\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;34m'124.243.226.18:8888'\u001B[0m\u001B[1;33m}\u001B[0m\u001B[1;33m,\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m----> 7\u001B[1;33m     \u001B[1;33m{\u001B[0m\u001B[1;33m}\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m      8\u001B[0m }\n\u001B[0;32m      9\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n",
      "\u001B[1;31mTypeError\u001B[0m: unhashable type: 'dict'"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "proxy={\n",
    "    {'http':'58.87.98.152:1011'},\n",
    "    {'https':'202.95.8.141:3128'},\n",
    "    {'https':'124.243.226.18:8888'},\n",
    "    {}\n",
    "}\n",
    "\n",
    "response=requests.get(\"https://www.bilibili.com/video/BV1GU4y1t7Bw\",proxies=proxy)\n",
    "\n",
    "print(response.text)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "[\n",
    "    {'http':'58.87.98.152:1011'},\n",
    "    {'https':'202.95.8.141:3128'},\n",
    "    {'https':'124.243.226.18:8888'},\n",
    "{'http':\"121.233.227.18:9999\"},\n",
    "{'http':\"223.215.18.246:9999\"},\n",
    "{'http':\"27.156.194.48:99991\"},\n",
    "{'http':\"117.69.170.62:9999\"},\n",
    "{'http':\"153.36.134.220:9999\"},\n",
    "{'http':\"114.233.170.48:8056\"},\n",
    "{'http':\"114.239.149.157:9999\"},\n",
    "{'http':\"114.98.174.108:9999\"},\n",
    "{'http':\"27.150.87.79:9999\"},\n",
    "{'http':\"49.89.87.80:9999\"},\n",
    "{'http':\"140.255.185.84\"},\n",
    "{'http':\"183.166.163.1873\"},\n",
    "{'http':\"182.46.247.12431\"},\n",
    "{'http':\"121.233.207.8831\"},\n",
    "{'http':\"36.56.101.51\"}]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}